package com.orm.analysis.dao;

import com.orm.analysis.model.Payment;
import com.orm.analysis.model.Salesman;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/12/13
 * Time: 2:18 PM
 * To change this template use File | Settings | File Templates.
 */
public class SalesmanDAO extends GenericJPADAO<Salesman, Integer> {

       public List<Salesman> list(int page, int size) {
           Query query = this.em.createQuery("from Salesman");
           query.setFirstResult((page - 1) * size);
           query.setMaxResults(size);
           return query.getResultList();
       }


       public Salesman getById(Integer id) {
             return this.em.find(Salesman.class,id);
       }


@Transactional
          @Override
          public void save(Salesman entity) {
               getEntityManager().persist(entity);
          }
}
